package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.UserRespository;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    UserRespository userRespository;
    @Autowired(required = false)
    UserDao userDao;

    @Override
    public List<User> findAll() {
        return userRespository.findAll();
    }

    @Override
    public User findById(Integer id) {
        return userRespository.findById(id).get();
    }

    @Override
    public User addAndUpdate(User user) {

        return userRespository.saveAndFlush(user);
    }

    @Override
    public void deleteById(Integer id) {
        userRespository.deleteById(id);
    }

    @Override
    public int regist(String phone, String pass) {
        return userDao.regist(phone,pass);
    }

    @Override
    public User login(String phone, String pass) {
        return userDao.login(phone,pass);
    }
}
